# abort 类似于 raise，在出现非预期情况的时候抛出异常

import sys
from pathlib import Path
from flask import Flask, abort, request, make_response, render_template


app = Flask(__name__)


@app.route("/", methods=["GET","POST"])
@app.route("/hello", methods=["GET", "POST"])
def hello():
    if request.method == "GET":
        return render_template("login.html")
    if request.method == "POST":
        name = request.form.get("UserID")
        passwd = request.form.get("Password")
        if name == "zhangsan" and passwd == "123":
            return "登录成功"
        else:
            # 一般是会输出404或者显示404以实现通知用户页面不存在
            abort(404)
            return False


# 自定义错误处理方法，404将调用下面的消息
@app.errorhandler(404)
def handler_404_error(err):
    return render_template("404.html")
    # return f"出现了404错误，错误信息为：{err}"

if __name__ == "__main__":
    app.run()